package servlets;

import java.io.IOException;
import java.util.TreeSet;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.MockRoomRepo;
import model.RoomRepo;
import model.User;

/**
 * Servlet implementation class UserRoomServlet
 */
public class UserRoomServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private RoomRepo room_repo = MockRoomRepo.getInstance();

    /**
     * @see HttpServlet#HttpServlet()
     */
    public UserRoomServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	  RequestDispatcher dispacher;
	  TreeSet<User> u = null;
		String name = null;

		name = request.getParameter("name");
		if(name!=null){
		  u = (TreeSet<User>)room_repo.getRoom(name).getUsers();
		  request.setAttribute("users", u);
		  dispacher = getServletContext().getRequestDispatcher("/userroomlist.jsp");
	    dispacher.forward(request, response);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
